﻿using AutoMapper;
using YDT_PaymentService.Applictions.DTOs;
using YDT_PaymentService.Domain.Entities;

namespace YDT_PaymentService.Applictions.Mappings
{
    /// <summary>
    /// AutoMapper映射配置 - 定义DTO和实体之间的映射规则
    /// </summary>
    public class MappingProfile : Profile
    {
        public MappingProfile()
        {
            // 支付映射配置
            CreateMap<Payment, PaymentDto>()
                .ForMember(dest => dest.PaymentStatus,
                           opt => opt.MapFrom(src => src.PaymentStatus.ToString()))
                .ForMember(dest => dest.PaymentType,
                           opt => opt.MapFrom(src => src.PaymentType.ToString()));

            // 创建支付映射配置
            CreateMap<CreatePaymentDto, Payment>();

            // 更新支付映射配置
            CreateMap<UpdatePaymentDto, Payment>()
                .ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null));
        }
    }
}
